#ifndef CRAPCONN_H
#define CRAPCONN_H

#include "connect.h"
#include "tbllim.h"
#include "DiceGameIds.h"
#include "tracksql.h" 

class DiceGame;
class CrapsRound;
class GameDBInterface;

#define CRAPS_GAMEID_SIZE		16
typedef char CrapsGameID[CRAPS_GAMEID_SIZE];


class CrapsConnection : public Connection
{
	public:
		CrapsConnection(Server* server, SOCKET client);
		~CrapsConnection();

		// messages
		void	msgStart();
		void	msgAdd(uint8 Byte);
		void	msgAdd(int32 SignedLong);
		uint8*	msgGetBuf();
		void	msgReleaseBuf(int32 Amt);
		void	msgEnd();

		// accessors		
        DiceGameIds getCurrentGameId() { return m_eGameId; }
        inline GameDBInterface * getGameDBInterface() { return m_pDBInterface; } 


        // kharmon.  06-19-06.  #3077.  Sic Bo implementation.  Moved this here so that all game types can use it.
        struct Info
        {
	        String			login;
	        PID				pid;
	        SESSIONID		sessionId;
	        CrapsGameID		gid;
	        bool8			forMoney;
        };

        Info * getCasinoSpecificInfo() { return casinoSpecific; }

		int32	msgRemove(uint8*, uint8*);
		int32	msgRemove(uint8*, int32*);

        void trackaddBadPacket(int32 error_reason, char MessageType, char *msgbuf, int32 msglen);
		int32 trackValidateLogin();
		int32 trackValidateSession();

		void	trackLogoutSession();

		uint8   getForcedRoll();
		bool8   isForcedRoll() {return m_bForcedRolls;}

	protected:
		bool8	getResponse();

		void	sendStopMsg();

		bool8	parseAnsiCasinoLogin(int32*);
		bool8	parseUnicodeCasinoLogin(int32*);
		void	handleLogin(int32 len);

		void	removeCasinoSpecific();

		int32	encode(uint8*, uint8*, int32);
		int32	decode(uint8*, uint8*, int32);

		void	allocateXMLTranslator( XMLTranslator** target );

		void	checkForcedRolls(String login);
		uint8	*m_iForcedRollValues;
		int32	m_iForcedRollCount;
		int32   m_iForcedRollRound;
		bool8	m_bForcedRolls;

	protected:

		int32			loggedOn;        // has the player successfully logged in?
		int32			balance;         // player's last known balance

        DiceGameIds     m_eGameId;       // kharmon.  06-19-06.  #3077.  Type of current game attached to this connection.
		DiceGame		*game;	         // Pointer to current game object, either sic bo or craps.
        GameDBInterface *m_pDBInterface; // Pointer to current game's database object.

		Info*			casinoSpecific;  // information about the player connection
		int32			msglen;          // length of current message
		uint8			msgbuf[512];     // buffer holding current message

	// [AO 2008-01-16] Refactoring for HA
	private:
		bool ValidateSession();
};

#endif
